<?php
	session_start();	
	require 'extras\dbConnect.php';
	$_SESSION["logged"] = true;
	
//	unset($_SESSION["logged"]);
?>

<html>
<head>
    	<title>ICS SAIS</title>
        
<link href="style/design.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript">
	 var RecaptchaOptions = { theme : 'white' };
	
	function form_type_display() {
		disable_all_forms();
		if (document.getElementById('type').value == 'student') {
			var className = 'student_form';
		} else if(document.getElementById('type').value == 'faculty'){
			var className = 'faculty_form';
		} else if(document.getElementById('type').value == 'encoder'){
			var className = 'encoder_form'
		}
		
		<!--get elements by class-->
		<!--http://stackoverflow.com/questions/3808808/how-to-get-element-by-class-in-javascript-->
		var elems = document.getElementsByTagName('*'), i;
		for (i in elems) {
			if((' ' + elems[i].className + ' ').indexOf(' ' + className + ' ')
					> -1) {
				elems[i].style.display = 'table-row';
				elems[i].required = "true";
			}
		}
	}
	
	function disable_all_forms(){
		var elems = document.getElementsByTagName('*'), i;
		var form_names = new Array();
		form_names[0] = 'student_form';
		form_names[1] = 'faculty_form';
		form_names[2] = 'encoder_form';
		for (h in form_names){
			for (i in elems) {
				if((' ' + elems[i].className + ' ').indexOf(' ' + form_names[h] + ' ')
						> -1) {
					elems[i].style.display = 'none';
					elems[i].required = "false";
				}
			}
		}
	}
	
	
</script>       

</head>
    
<body>
   	<div id="cont">
        	<div id="header">
            	<div id="header_main">
                	<div id="mhleft">
                    </div>
                    
                    <div id="mhcenter" ice:editable="*">
                    	<img src="style/ics_logo_blue.png" id="logo"/>
                      <div id="label_sais">
                        	<div id="border_label">	</div>
                        <div id="label"><p>Students'Academic
Information System</p></div>
                      </div>
                  </div>
                    
                    <div id="mhright">
                    </div>
                </div>
<?php
	
?>     
                <div id="bottomhead">
                	<div id="bhleft">
                    </div>
                    <div id="menu_bar">
                    	<!--login-->
                          <table>
                            <tr><td><label for="welcome">Welcome <?=$_SESSION['user']?>!</label></td></tr>
                          </table>
                    </div>
                </div>
            </div>
      <div id="body">
      	<div id="body_border">
        </div>
        <div id="forms">
        	<?
        	$student_array = array();
			$user = $_SESSION['user'];
			$query = "SELECT username FROM accounts_active WHERE account_type='student'";
			$result = mysql_query($query, $connection) or die("Error in query: $query." .mysql_error($result));
			$rows = mysql_num_rows($result); // get the number of rows in the resultset
			if ($rows > 0){// iterate through resultset?>
				<div>
					<table id='viewTeam-Table'>
						<th class="viewScores">All students</th>
						<?for ($i=0; $i<$rows; $i++){
					 		$row = mysql_fetch_object($result);?>
					 		<tr id="striped">
					 			<?
					 				$student_array[] = $row->username; 	 			
					 			?>
					 		</tr>
						<?}
						?>
					</table>
				</div>
			<?}?>
			<?
			foreach ($student_array as $student) {


				$query = "SELECT * FROM student WHERE Email_Address='".$student."'";
				$result = mysql_query($query, $connection) or die("Error iu query: $query." .mysql_error($result));
				$rows = mysql_num_rows($result); // get the number of rows in the resultset
				if ($rows > 0){// iterate through resultset?>
					<div>
						<table id='viewTeam-Table'>
							<?for ($i=0; $i<$rows; $i++){
						 		$row = mysql_fetch_object($result);?>
						 		<tr id="striped">
						 			<?echo($row->Email_Address);?>
						 		</tr>
							<?}
							mysql_close($connection);// close database connection?>
						</table>
					</div>
				<?}?>
			<?}?>
        </div>
<?php
	
	//else if logged in
	//redirect to user page
?>
      </div>
   	</div>
    </body>
</html>